#include <stdio.h>

#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define exch(A, B) {node t = A; A = B; B = t;} 
#define cmpexch(A, B) if (less(B, A)) exch(A, B)

typedef int node;
int partition(node x[], int l, int r);
int select(node x[], int l, int r, int k);

int main() {
  node v[5] = {1,3,8,3,4};
  printf("%i", select(v, 0, 4, 1));
  return 0;
}

int partition(node x[], int l, int r)
{ int i = l-1, j = r; node v = x[r];
  for (;;)
    { 
      while (less(x[++i], v)) ;
      while (less(v, x[--j])) if (j == l) break;
      if (i >= j) break;
      exch(x[i], x[j]);
    }
  exch(x[i], x[r]);
  return i;
}

int select(node x[], int l, int r, int k)
{ 
  int i;
  if (r <= l) return;
  i = partition(x, l, r);
  if (i > k) select(x, l, i-1, k);
  if (i < k) select(x, i+1, r, k);
}

